import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import goodsRoutes from './modules/goods.js'
import cartRoutes from './modules/cart.js'
import centerRoutes from './modules/center.js'
import olistRoutes from './modules/olist.js'

const routes = [
  //路由重定向
  {
    path: '/',
    redirect: '/index'
  },
  //商品主页
  ...goodsRoutes,
  //购物车
  ...cartRoutes,
  //个人中心
  ...centerRoutes,
  //订单列表
  ...olistRoutes

]

import store from "@/store/index"
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, form, next) => {
  let quanxian = [
    
    "/install",
    "/map",
    "/coupon",
    "/ContactCard",
    "/no",];

  let toPath = to.path;
  if (quanxian.includes(toPath)) {
    if (store.state._token) {
      next();
    } else {
      router.push({
        path: "/login",
        query: { callback: toPath }
      })
    }
  } else {
    next();
  }
})
export default router
